import { createApp } from "vue";
import App from "./App.vue";

import jmash, {
  store,
  routerRef,
  directive,
  useUserStore,
  getQueryParams,
  i18n,
  updateViteMetaEnv,
  axiosConfig,
  testRoutes,
  createNewRouter
} from "./index";

//环境变量
const viteMetaEnv: ImportMetaEnv = import.meta.env;
const metaEnv = updateViteMetaEnv(viteMetaEnv);
const newRouter = createNewRouter(metaEnv.APP_BASE_URL);
axiosConfig(metaEnv);

const app = createApp(App);

testRoutes.forEach((route: any) => {
  newRouter.value.addRoute(route);
});

import { addRoutePerm } from "@/permission";
addRoutePerm(newRouter.value);

//Query参数
const queryParams = getQueryParams();
if (queryParams.tenant) {
  useUserStore().user.tenant = queryParams.tenant;
} else {
  useUserStore().user.tenant = "rbac";
}

import VConsole from "vconsole";
const vConsole = new VConsole();

app.use(jmash).use(store).use(directive).use(routerRef.value).use(i18n).mount("#app");

//vConsole.destroy();
